---@diagnostic disable: need-check-nil
local utils = {}

utils.about = function()
  local status, popup = pcall(require, "nui.popup")
  if not status then
    error("nui.nvim required")
  end

  local line = require("nui.line")
  local width = 80

  local p = popup({
    enter = true,
    focusable = true,
    border = {
      style = "single",
      text = {
        top = "XPERA",
        top_align = "center",
        bottom = "Press q or n to close window",
        bottom_align = "center",
      },
    },
    buf_options = {
      modifiable = true,
      readonly = false,
    },
    position = "50%",
    size = {
      width = tostring(width),
      height = "30%",
    },
  })

  p:mount()

  local function render(content, row)
    local l = line()
    l:append(content)
    l:render(p.bufnr, -1, row)
  end

  render("", 1)
  render("", 2)
  render("", 3)
  render(
    "            ██╗      █████╗ ███████╗██╗   ██╗██╗   ██╗██╗███╗   ███╗",
    4
  )
  render(
    "            ██║     ██╔══██╗╚══███╔╝╚██╗ ██╔╝██║   ██║██║████╗ ████║",
    5
  )
  render(
    "            ██║     ███████║  ███╔╝  ╚████╔╝ ██║   ██║██║██╔████╔██║",
    6
  )
  render(
    "            ██║     ██╔══██║ ███╔╝    ╚██╔╝  ╚██╗ ██╔╝██║██║╚██╔╝██║",
    7
  )
  render(
    "            ███████╗██║  ██║███████╗   ██║    ╚████╔╝ ██║██║ ╚═╝ ██║",
    8
  )
  render(
    "            ╚══════╝╚═╝  ╚═╝╚══════╝   ╚═╝     ╚═══╝  ╚═╝╚═╝     ╚═╝",
    9
  )
  render("                                                              NEOVIM", 10)
  render("", 11)
  render("                                     XPERA", 12)

  p:map("n", "q", function()
    p:unmount()
  end, { noremap = true, silent = true })

  p:map("n", "n", function()
    p:unmount()
  end, { noremap = true, silent = true })

  vim.api.nvim_buf_set_option(p.bufnr, "modifiable", false)
  vim.api.nvim_buf_set_option(p.bufnr, "readonly", true)
end

return utils
